You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@floating-ui/utils

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@floating-ui/utils

Utilities for Floating UI

0.2.10
latest
Source
npmnpm
Version published
Weekly downloads
20M
2.83%
Maintainers
2
Weekly downloads
 
Created

What is @floating-ui/utils?

The @floating-ui/utils package provides utility functions for positioning floating elements (like tooltips, popovers, dropdowns, etc.) in relation to reference elements in the DOM. It is part of the Floating UI library, which offers a low-level toolkit for creating floating elements.

What are @floating-ui/utils's main functionalities?

computePosition

This feature calculates the position of a floating element relative to a reference element and applies the calculated position to the floating element.

import {computePosition} from '@floating-ui/dom';

const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');

computePosition(referenceElement, floatingElement).then(data => {
  Object.assign(floatingElement.style, {
    left: `${data.x}px`,
    top: `${data.y}px`,
  });
});

arrow

The arrow utility positions an arrow element within a floating element so that it is properly aligned with the reference element.

import {computePosition, arrow} from '@floating-ui/dom';

const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');
const arrowElement = floatingElement.querySelector('#arrow');

computePosition(referenceElement, floatingElement, {
  middleware: [arrow({element: arrowElement})],
}).then(data => {
  Object.assign(floatingElement.style, {
    left: `${data.x}px`,
    top: `${data.y}px`,
  });
  Object.assign(arrowElement.style, data.middlewareData.arrow);
});

autoPlacement

The autoPlacement utility automatically chooses the best placement for a floating element based on available space in the viewport.

import {computePosition, autoPlacement} from '@floating-ui/dom';

const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');

computePosition(referenceElement, floatingElement, {
  middleware: [autoPlacement()],
}).then(data => {
  Object.assign(floatingElement.style, {
    left: `${data.x}px`,
    top: `${data.y}px`,
  });
});

flip

The flip utility adjusts the placement of the floating element to prevent it from overflowing the viewport.

import {computePosition, flip} from '@floating-ui/dom';

const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');

computePosition(referenceElement, floatingElement, {
  middleware: [flip()],
}).then(data => {
  Object.assign(floatingElement.style, {
    left: `${data.x}px`,
    top: `${data.y}px`,
  });
});

offset

The offset utility adds space between the reference element and the floating element, defined by the offset value.

import {computePosition, offset} from '@floating-ui/dom';

const referenceElement = document.querySelector('#reference');
const floatingElement = document.querySelector('#floating');

computePosition(referenceElement, floatingElement, {
  middleware: [offset(10)],
}).then(data => {
  Object.assign(floatingElement.style, {
    left: `${data.x}px`,
    top: `${data.y}px`,
  });
});

Other packages similar to @floating-ui/utils

Keywords

tooltip

FAQs

Package last updated on 28 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts